package com.zjpavt.taiyuan.controller.base;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;

import java.text.DateFormat;

/**
 * code值的含义请在ResponseCode里详细说明<br>
 *
 * @author lixun
 */
public class ResponseResult {
    public ResponseResult(int code, String message, Object data) {
        this.code = code;
        //msg与data如果为空则，直接赋值为空字符串，防止返回属性中不含msg与data
        this.message = message == null ? "" : message;
        this.data = data;
    }

    @Override
    public String toString() {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(java.util.Date.class, new DateSerializer()).setDateFormat(DateFormat.LONG);
        gsonBuilder.excludeFieldsWithoutExposeAnnotation();
        Gson gson = gsonBuilder.create();
        String str = gson.toJson(this);
        return str;
    }

    @Expose
    private int code;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    @Expose
    private String message;

    public String getMessage() {
        return message;
    }

    public void setMessage(String msg) {
        this.message = msg;
    }

    @Expose
    private Object data;

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}
